package com.ybwh.springboot1.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ybwh.springboot1.dao.DictDao;
import com.ybwh.springboot1.model.po.Dict;
import com.ybwh.springboot1.model.vo.DataTabelPageVo;

/**
 * @author fan
 *
 */
@Service
public class DictService {
	@Autowired
	private DictDao dictDao;

	/**
	 * 分页查询
	 * 
	 * @param dictGroup
	 * @param start
	 * @param length
	 * @return
	 */
	public DataTabelPageVo<Dict> pageList(Map<String, Object> param, int start, int length) {

		return dictDao.pageList(start, length, param);

	}

	public void addOrUpdate(Dict dict) throws Exception {
		if (null == dict) {
			throw new IllegalArgumentException();
		}
		
		Date now = new Date();
		dict.setUpdateTs(now);
		dict.setUpdateId(0L);
		if (null == dict.getId()) {
			dict.setCreateTs(now);
			dict.setCreateId(0L);
			dictDao.insert(dict);
		} else {
			dictDao.update(dict);
		}

	}

	public List<Dict> queryByGroup(String dictGroup) {
		if(StringUtils.isBlank(dictGroup)) {
			throw new IllegalArgumentException();
		}
		
		return dictDao.queryByGroup(dictGroup);
	}

}
